/*    file: main.cpp
 *    desc:
 * 
 * created: 2016-04-06
 *  author: chuanjiang.zh@qq.com
 * company: 
 */

#include <stdio.h>
#include <iostream>


#include <assert.h>
#include <errno.h>
#include <string>
#include <memory>
#include <algorithm>

#include "LibMediaDecoder.h"


class Application
{
public:
	Application()
	{
		MDecode_Init();
	}

	~Application()
	{
		MDecode_Uninit();
	}

	static void decodeCallback(HANDLE handle, MDecode_Frame* frame, void* pUser)
	{
		printf("frame. width: %d, height: %d, pts: %lld\n", frame->width, frame->height, frame->pts);
	}

};


int main(int argc, char** argv)
{
	std::string filename = "rtsp://admin:sjld16301@192.168.3.65/";

	if (argc > 1)
	{
		filename = argv[1];
	}

	Application app;

	HANDLE handle = MDecode_CreateHandle();
	BOOL ret = MDecode_OpenFileEx(handle, filename.c_str(), "");
	MDecode_SetDecodeCallback(handle, MDECODE_PIXEL_BGR24, Application::decodeCallback, &app);

	MDecode_Play(handle);

	while (true)
	{
		std::string line;
		std::getline(std::cin, line);
		if (line == "q")
		{
			break;
		}
	}

	MDecode_CloseFile(handle);
	MDecode_DestroyHandle(handle);

	return 0;
}
